package top.aicey.ai.sparring.common.holder;

import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by Gavin on 2017/6/20.
 * Update by Joshua on 2017-7-21.
 */
public class UserHolder {

    private static final ThreadLocal<CurrentUser> contextHolder = new ThreadLocal<>();

    public static CurrentUser getUser() {
        return contextHolder.get();
    }

    public static void setUser(String user) {
        if (StringUtils.isEmpty(user)) {
            return;
        }
        CurrentUser currentUser = JSON.parseObject(user, CurrentUser.class);

        contextHolder.set(currentUser);
    }

    public static void setUser(CurrentUser currentUser) {
        contextHolder.set(currentUser);
    }
}


